package com.yunlan.materia.enums;

import java.util.EnumSet;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author 罗显
 * @date 2025/9/18
 * @ApiNote
 */
public enum BaseStatusEnum {
    NORMAL(0, "正常"),
    DISABLE(1, "禁用");

    private Integer code;
    private String  msg;

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    /**
     * 根据code 找到desc 描述
     */
    private static final Map<Integer, BaseStatusEnum> VALUE_LOOKUP = new ConcurrentHashMap<>(values().length);
    static {
        for (BaseStatusEnum type: EnumSet.allOf( BaseStatusEnum.class)){
            VALUE_LOOKUP.put(type.code, type);
        }
    }

    BaseStatusEnum(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public static BaseStatusEnum fromValue(Integer code) {
        BaseStatusEnum data = VALUE_LOOKUP.get(code);
        if (data == null) {
            throw new IllegalArgumentException("参数[" + code + "]不正确，没有找到对应的 Enum");
        }
        return data;
    }

}
